import { Game, GameComponent } from "@sapi-game/main";
import { EffectIds } from "@sapi-game/utils/vanila-data";
import { eleMainState } from "../state";
import { EquipmentSlot } from "@minecraft/server";

export class ElevatorMainDaemon extends GameComponent<eleMainState> {
    override onAttach(): void {
        this.subscribe(Game.events.interval, () => {
            this.context.group.forEach((p) =>
                p.player?.addEffect(EffectIds.Resistance, 100, {
                    amplifier: 10,
                    showParticles: false,
                })
            );
        });
        //生命显示
        this.subscribe(
            Game.events.inSlot,
            (t) => {
                const p = this.context.mouse.getById(t.player.id);
                if (p) {
                    p.actionbar(`剩余 §c${p.lives}§r 条命`);
                }
            },
            {
                slot: EquipmentSlot.Mainhand,
                itemId: "minecraft:redstone_block",
                group: this.context.mouse,
            }
        );
    }
}
